#include "timeout_exception.hpp"
#include <iostream>
#include <cassert>

using namespace timeout_manager;

// g++ -std=c++17 -o test_exception test_exception.cpp

void testTimeoutException() {
    std::cout << "=== 测试 TimeoutException ===" << std::endl;
    
    try {
        // 创建并抛出超时异常
        throw TimeoutException("Task execution timed out after 5 seconds");
    } catch (const TimeoutException& e) {
        std::cout << "捕获到超时异常: " << e.what() << std::endl;
        // 验证异常消息是否正确
        assert(std::string(e.what()) == "Task execution timed out after 5 seconds");
        std::cout << "✓ 异常消息正确" << std::endl;
    }
    
    std::cout << std::endl;
}

void testTaskHandle() {
    std::cout << "=== 测试 TaskHandle ===" << std::endl;
    
    // 创建任务句柄
    TaskHandle handle1(12345);
    TaskHandle handle2(12345);
    TaskHandle handle3(67890);
    
    // 测试ID获取
    std::cout << "任务句柄1的ID: " << handle1.getId() << std::endl;
    assert(handle1.getId() == 12345);
    std::cout << "✓ ID获取正确" << std::endl;
    
    // 测试相等性比较
    assert(handle1 == handle2);  // 相同ID应该相等
    assert(!(handle1 == handle3)); // 不同ID应该不相等
    std::cout << "✓ 相等性比较正确" << std::endl;
    
    std::cout << std::endl;
}

int main() {
    std::cout << "开始测试基础组件..." << std::endl << std::endl;
    
    testTimeoutException();
    testTaskHandle();
    
    std::cout << "所有基础组件测试通过！" << std::endl;
    return 0;
}